
<template>
  <div class="w order">
    <div class="flex-box">
      <div class="flex-item">
        <div class="img-bg"></div>
      </div>
      <div class="flex-item color-bg">
        <div class="object-titile">
          <h3>项目代码智能分析系统</h3>
        </div>
        <div class="object-titile">
          <span class="price-class">￥:99.99</span>
          <a-divider type="vertical" />
          <a-rate :disabled="true" :value="5" />
        </div>
        <div class="object-titile">
          <span
            class="color-span-size">项目代码智能分析系统是一款帮助开发者分析代码的工具，采用扁平风格的界面设计，能够智能分析项目的框架、结构和代码质量。通过集成chagpt等代码解析工具，能够帮助开发者更好地理解和优化项目代码。</span>
        </div>
        <div class="object-titile">
          <div>
            <span class="yuyan-class">语言</span>
            <div class="border-code-top">
              <div class="border-code-div">Java</div>
            </div>
          </div>
        </div>
        <div class="object-titile">
          <div>
            <span class="yuyan-class">功能</span>
            <div class="border-code-top">
              <div class="border-code-div">源码解析</div>
            </div>
          </div>
        </div>
        <div class="object-titile">
          <div class="pay" @click="requestPay">
            立即支付
          </div>
        </div>


        <div class="object-titile">
          <div>
            <span class="bootom-linl-class">功能特点:</span>
            <div class="bg-color-class">
              项目代码智能分析系统是一款功能强大的工具，提供多种代码分析功能，包括代码结构分析、代码质量评估、代码性能分析和代码安全漏洞检测等。同时，系统还提供详细的使用说明和技术支持，帮助开发者更好地使用和理解工具。</div>

          </div>

        </div>


      </div>
    </div>

    <a-modal v-model:open="open" title="立即支付" @ok="open = false">
      <div class="pay_image">
        <a-image :width="200" :height="200" :preview="false" :src="srcPath"
          fallback="https://gw.alipayobjects.com/zos/antfincdn/LlvErxo8H9/photo-1503185912284-5271ff81b9a8.webp">
          <template #placeholder>
            <div class="loader">

            </div>
          </template>
        </a-image>
      </div>
    </a-modal>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { builderPay } from '@/api/pay.js'
import { message } from "ant-design-vue";

const open = ref(false)
const srcPath = ref('')
const socketMessageHandle = () => {

}
const requestPay = async () => {
  // 创建订单
  const { data, message: msg, code } = await builderPay()
  if (msg !== '操作失败' && code !== 201) {
    open.value = true
    srcPath.value = `data:image/jpeg;base64,${data.payImage}`
    // 创建连接
    const socket = new WebSocket(`ws://localhost:8888/api/websocket`);
    socket.addEventListener('open', function (event) {
      socket.send(JSON.stringify({
        orderNo: data.orderNo
      }));
    });

    // 监听 WebSocket 接收到消息事件
    socket.addEventListener('message', function (event) {
      const { status } = JSON.parse(event.data||{})
      if (status === 1) {
        open.value = false;
        message.success("支付成功");
        socket.close();
      }
      console.log('Message from server:', event.data);
    });
  }
}
</script>

<style scoped lang="scss">
.flex-box {
  .bootom-linl-class {
    border-bottom: 2px solid black;
  }

  .bg-color-class {
    color: #737373;
  }

  .border-code-top {
    margin-top: 10px;
    display: flex;
    width: calc(60px*1);
    justify-content: space-around;

    .border-code-div {
      width: 90px;
      height: 30px;
      font-size: 10px;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 5px;
      border: 1px solid rgb(103, 103, 103);
    }
  }

  .yuyan-class {
    color: #bbbbbb;
  }

  display: flex;
  justify-content: center;
  height: 30vw;

  .flex-item {
    width: 40%;
    background-color: white;
    border-top-right-radius: 10px;
    border-top-left-radius: 10px;
  }

  .img-bg {
    width: 100%;
    height: 100%;
    background-size: 100%;
    background-image: url('../.././assets/images/1721721288398.png');
  }

  .color-bg {
    padding-left: 2vw;
  }

  .object-titile {
    margin-top: 1vw;
    display: flex;
    justify-content: left;
    align-items: center;
  }

  .color-span-size {
    font-size: 16px;
  }

  .price-class {
    font-weight: bolder;
  }
}

:deep() {
  .ant-rate {
    font-size: 12px !important;
    margin-bottom: 5px;
  }
}

.loader {
  width: 200px;
  height: 200px;
  aspect-ratio: 1;
  --_c: no-repeat radial-gradient(farthest-side, #25b09b 92%, #0000);
  background:
    var(--_c) top,
    var(--_c) left,
    var(--_c) right,
    var(--_c) bottom;
  background-size: 12px 12px;
  animation: l7 1s infinite;
}

@keyframes l7 {
  to {
    transform: rotate(.5turn)
  }
}

.pay_image {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.order {
  h2 {
    text-align: center;
    color: rgb(255, 215, 0);
    font-size: 40px;
    margin-bottom: 20px;
    margin-top: 40px;
  }

  p {
    margin-bottom: 30px;
    text-indent: 2em;
    color: #dedede;
    line-height: 2;
  }

  .pay {
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100px;
    height: 40px;
    background: rgb(225, 215, 0);
    border-radius: 10px;
    font-weight: bold;
    font-size: 10px;
    color: #ffffff;
  }
}
</style>